package com.tanhua.server.controller;

import com.tanhua.server.service.TestSoulService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.tanhua.model.vo.AnswersVo;
import com.tanhua.model.vo.QuestionnaireReportVo;
import com.tanhua.model.vo.QuestionnaireVo;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/testSoul")
public class TestSoulController {

    @Autowired
    private TestSoulService testSoulService;

    /**
     * 测灵魂-问卷列表
     * GET/testSoul
     */
    @GetMapping
    public ResponseEntity questionnaireList() {
        List<QuestionnaireVo> list = testSoulService.questionnaireList();
        return ResponseEntity.ok(list);
    }

    /**
     * 测灵魂-提交问卷
     * POST/testSoul
     */
    @PostMapping
    public ResponseEntity commitQuestionnaire(@RequestBody Map<String, List<AnswersVo>> answers) {
        String reportId = testSoulService.commitQuestionnaire(answers);
        return ResponseEntity.ok(reportId);
    }

    /**
     * 测灵魂-查看报告
     * GET/testSoul/report/:id
     */
    @GetMapping("/report/{id}")
    public ResponseEntity getReport(@PathVariable("id") Long id) {
        QuestionnaireReportVo vo = testSoulService.getReport(id);
        return ResponseEntity.ok(vo);
    }
}
